<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" href="/plugins/layui/css/layui.css">
</head>
<body>
<div class="layui-tab-content">
    <form class="layui-form" lay-filter="jobForm" style="padding-right: 15px;">
        <input type="hidden" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">任务名称：</label>
            <div class="layui-input-block">
                <input type="text" name="jobName" lay-verify="required" placeholder="请输入任务名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">任务描述：</label>
            <div class="layui-input-block">
                <input type="text" name="description" lay-verify="required" placeholder="请输入任务描述" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">bean名称：</label>
            <div class="layui-input-block">
                <input type="text" name="beanName" lay-verify="required" placeholder="请输入类的bean名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">方法名称：</label>
            <div class="layui-input-block">
                <input type="text" name="methodName" lay-verify="required" placeholder="请输入方法名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">方法参数：</label>
            <div class="layui-input-block">
                <input type="text" name="methodParams" placeholder="请输入方法参数" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">cron表达式：</label>
            <div class="layui-input-block">
                <input type="text" name="cronExpression" lay-verify="required" placeholder="请输入cron表达式" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit lay-filter="submitForm">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</body>

<script src="/plugins/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form'], function () {
        var $ = layui.jquery,
            form = layui.form;

        var data = parent.data;
        if (data) {
            form.val("jobForm", {
                "id": data.id,
                "jobName": data.jobName,
                "description": data.description,
                "beanName": data.beanName,
                "methodName": data.methodName,
                "methodParams": data.methodParams,
                "cronExpression": data.cronExpression
            });
        }

        // 监听提交表单
        form.on('submit(submitForm)', function (data) {
            var loadIndex = layer.load(2);
            $.ajax({
                type: "post",
                url: "/job/save",
                data: data.field,
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200) {
                        layer.msg('保存成功！', {icon: 1});
                        // 刷新列表
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layui.table.reload('currentTableId',{page: {curr: 1}});
                        parent.layer.close(index);
                    } else {
                        layer.alert(res.msg, {icon: 2, title: "提示"});
                    }
                },
                error: function (res) {
                    layer.close(loadIndex);
                    layer.alert(res.msg, {icon: 2, title: '提示'});
                }
            });
            return false;
        });

    });
</script>

</html>